package com.xsherl.leetcode.solution;

public class CanCross {

    public boolean canCross(int[] stones) {
        int step = 1;
        for (int i = 0; i < stones.length - 1; ) {
            if (stones[i + step + 1] - stones[i] <= step + 1) {
                step = stones[i + step + 1] - stones[i];
                i = i + step;
            } else if (stones[i + step] - stones[i] <= step) {
                step = stones[i + step] - stones[i];
                i = i + step;
            } else if (stones[i + step - 1] - stones[i] > 0 && stones[i + step - 1] - stones[i] <= step - 1) {
                step = stones[i + step - 1] - stones[i];
                i = i + step;
            } else {
                return false;
            }
        }
        return true;
    }

}
